import {UserActions} from './user';

const initialState = {
  total: 1,
  count: 1,
  current: 1,
  results: [],
};

export const SupplierCommentActions = {
  SUPPLIER_COMMENT_UPDATE: 'supplier_comment_update',
  SUPPLIER_COMMENT_RESET: 'supplier_comment_reset',
};

export function updateSupplierComment(payload) {
  return {
    type: SupplierCommentActions.SUPPLIER_COMMENT_UPDATE,
    payload,
  };
}

export function resetSupplierComment() {
  return {
    type: SupplierCommentActions.SUPPLIER_COMMENT_RESET,
  };
}

export default function supplierCommentList(state = initialState, action) {
  switch (action.type) {
    case SupplierCommentActions.SUPPLIER_COMMENT_UPDATE:
      return {...state, ...action.payload};
    case SupplierCommentActions.SUPPLIER_COMMENT_RESET:
      return {
        total: 1,
        count: 1,
        current: 1,
        results: [],
      };
    case UserActions.USER_SIGN_OUT:
      return {
        total: 1,
        count: 1,
        current: 1,
        results: [],
      };
    default:
      return state;
  }
}
